package com.example.spinning.service;

import com.example.spinning.bean.OutStock;
import com.example.spinning.mapper.OutStockMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class OutStockService {

    @Autowired
    private OutStockMapper outStockMapper;

    //得到出库单信息
    //带有分页功能的展现数据
    public List<OutStock> getAllOutStock(Integer page, Integer count) {
        int start = (page - 1) * count;
        return outStockMapper.getOutStock(start,count);
    }

    //找到行数
    public int getOutStockCount() {
        return outStockMapper.getCountOutStock();
    }

    //根据条件找到行数
    public int getOutStockCountByCondition(String date,String receiver,String norms,String batch_no) {
        return outStockMapper.getCountOutStockByCondition(date,receiver,norms,batch_no);
    }

    //根据id查询出库单信息
    public OutStock getOutStockById(long id){
        OutStock stock = outStockMapper.getOutStockById(id);
        return stock;
    }

    //根据条件模糊查询
    public List<OutStock> getOutStockByCondition(Integer page, Integer count,String date,String receiver,String norms,String batch_no){
        int start = (page - 1) * count;
        return outStockMapper.getOutStockByCondition(start,count,date,receiver,norms,batch_no);
    }

    //添加出库单信息
    public int addOutStock(OutStock stock){
        return outStockMapper.addOutStock(stock);
    }


    //修改
    public int updateOutStock(OutStock stock){
        return outStockMapper.updateOutStockById(stock);
    }

    //删除
    public boolean deleteOutStockByIds(String ids){
        String[] split = ids.split(",");
        int result = outStockMapper.delOutStockById(split);
        return result == split.length;
    }


}
